#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class SetNum {
public:
    void operator()(int& value) const {
        value = rand() % 1000 + 1;
    }
};

class Print {
public:
    void operator()(const int& value) const {
        cout << value << " ";
    }

};

int main()
{
    srand(time(NULL));
    vector<int> vec1(10);
    vector<int> vec2(10);

    SetNum setNum;

    for_each(vec1.begin(), vec1.end(), setNum);


    cout << "伪函数赋值后的容器内容：";
    for_each(vec1.begin(), vec1.end(), Print());

    
    for_each(vec2.begin(), vec2.end(), [](int& value) {
        value = rand() % 1000 + 1;
        });
    cout << endl;

    cout << "lambda赋值后的容器内容：";
    for_each(vec2.begin(), vec2.end(), Print());
    cout << endl;

    sort(vec1.begin(), vec1.end());
    sort(vec2.begin(), vec2.end());

    // 使用lambda函数输出排序后的容器内容
    cout << "排序后的vec1内容：";
    for_each(vec1.begin(), vec1.end(), [](const int& value) {
        cout << value << " ";
        });
    cout << endl;

    cout << "排序后的vec2内容：";
    for_each(vec2.begin(), vec2.end(), [](const int& value) {
        cout << value << " ";
        });
    cout << endl;

    return 0;
}
